package com.api.shopapi.mapper;

import com.api.shopapi.entity.JKNiaosuan;
import com.api.shopapi.entity.dto.JKNiaosuanDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface JKNiaosuanMapper {

    @Insert("insert into jk_niaosuan (JKNiaosuanCode,UserCode,NiaoSuan,FromType,InspectTime,CreateTime) values" +
            "(#{jkNiaosuan.JKNiaosuanCode},#{jkNiaosuan.UserCode},#{jkNiaosuan.NiaoSuan},#{jkNiaosuan.FromType}," +
            "#{jkNiaosuan.InspectTime},#{jkNiaosuan.CreateTime})")
    int insert(@Param("jkNiaosuan") JKNiaosuan jkNiaosuan);

    @Update("update jk_niaosuan set UserCode=#{jkNiaosuan.UserCode},NiaoSuan=#{jkNiaosuan.NiaoSuan}," +
            "FromType=#{jkNiaosuan.FromType},InspectTime=#{jkNiaosuan.InspectTime},CreateTime=#{jkNiaosuan.CreateTime} " +
            "where JKNiaosuanCode=#{jkNiaosuan.JKNiaosuanCode}")
    int update(@Param("jkNiaosuan") JKNiaosuan jkNiaosuan);

    @Delete("delete from jk_niaosuan where JKNiaosuanCode=#{jKNiaosuanCode}")
    int delete(@Param("jKNiaosuanCode") String jKNiaosuanCode);

    @Select("select * from jk_niaosuan where JKNiaosuanCode=#{jKNiaosuanCode} limit 1")
    JKNiaosuan getByJKNiaosuanCode(@Param("jKNiaosuanCode") String jKNiaosuanCode);

    @Select("select * from jk_niaosuan where UserCode=#{userCode} and InspectTime between #{startTime} and #{endTime} order by InspectTime desc")
    List<JKNiaosuan> getPageList(@Param("userCode") String userCode,@Param("startTime") String startTime,@Param("endTime") String endTime);

    @Select("<script>" +
            "select jn.*,u.Name as userName from jk_niaosuan jn left join user u on jn.UserCode=u.UserCode " +
            "where u.GovernmentCode=#{governmentCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and u.Name like concat('%',#{name},'%') " +
            "</if>" +
            "and jn.InspectTime between #{startTime} and #{endTime} " +
            "order by jn.InspectTime desc" +
            "</script>")
    List<JKNiaosuanDTO> getAdmPageList(@Param("name") String name, @Param("governmentCode") String governmentCode, @Param("startTime") String startTime, @Param("endTime") String endTime);

}
